package com.tg.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tg.mapper.ChatMapper;
import com.tg.pojo.Friend;
import com.tg.pojo.Message;
import com.tg.pojo.User;
import com.tg.service.ChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ChatServiceImpl implements ChatService {

    @Autowired
    private  ChatMapper chatMapper;

    @Override
    public boolean saveMessage(Message message) {
        int flag = chatMapper.insert(message);
        return flag >= 1;
    }

    @Override
    public List<Message> getMessageHistoryList(String fromUsername,String toUsername) {
        LambdaQueryWrapper<Message> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Message::getFromUsername,fromUsername)
                .eq(Message::getToUsername,toUsername)
                .or()
                .eq(Message::getFromUsername,toUsername)
                .eq(Message::getToUsername,fromUsername);
        return chatMapper.selectList(lambdaQueryWrapper);
    }

    @Override
    public List<Message> getMessageList(String username) {
        return chatMapper.getMessageList(username);
    }
}
